package com.jbm.jbmsupplier.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.zp.utils.DataFormate;
import com.jbm.onehome.iface.PaybackEntity;

import java.util.List;

/**
 * Created by 家帮忙 on 2017/4/11.
 */

public class PledgeAdapter extends BaseAdapter {
    private Context context;
    private List<PaybackEntity> arr;

    public PledgeAdapter(Context context, List<PaybackEntity> arr) {
        this.context = context;
        this.arr = arr;
    }

    @Override
    public int getCount() {
        return arr.size();
    }

    @Override
    public Object getItem(int position) {
        return arr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder viewholder;
        if (convertView==null){
             convertView=View.inflate(context, R.layout.dsy_item_mingxi,null);
            viewholder=new Viewholder(convertView);
            convertView.setTag(viewholder);
        }else{
            viewholder= (Viewholder)convertView.getTag();
        }
        PaybackEntity polis = arr.get(position);
        initviewdate(viewholder,polis);
        return convertView;
    }
public void setDataAll(List<PaybackEntity> arrs){
    arr=arrs;
    notifyDataSetChanged();

}
    private void initviewdate(Viewholder viewho,PaybackEntity lis) {
        if (lis.getMemo()!=null){
        viewho.title.setText(lis.getMemo());
        }
        if (lis.getCreateDate()!=null){
        viewho.time.setText(DataFormate.formate(DataFormate.StringF,lis.getCreateDate()));}
//        if (lis.getAmount().intValue()>0) {
//            viewho.money.setText("+"+lis.getAmount().intValue());
//            viewho.money.setTextColor(Color.parseColor("#3791DC"));
//        }else{
        viewho.money.setText(lis.getAmount()+"");
        if(Float.parseFloat(lis.getAmount()+"")<0.0){
            viewho.money.setTextColor(Color.parseColor("#1f1f1f"));
        }else{
            viewho.money.setTextColor(Color.parseColor("#2495ee"));
        }




//        }
    }

//    class Viewholder{
//        TextView texuhao,tejines,texbianh,texriqi;
//        public Viewholder(View conver) {
//            texuhao=(TextView) conver.findViewById(R.id.texuhao);
//            tejines=(TextView) conver.findViewById(R.id.tejines);
//            texbianh=(TextView) conver.findViewById(R.id.texbianh);
//            texriqi=(TextView) conver.findViewById(R.id.texriqi);
//
//        }
//    }

        class Viewholder{
            public  TextView title,time,money,item_money_static;
        public Viewholder(View view) {
            title=(TextView)view.findViewById(R.id.item_money_title);
            time=(TextView)view.findViewById(R.id.item_money_time);
            money=(TextView)view.findViewById(R.id.item_money_money);
            item_money_static=(TextView)view.findViewById(R.id.item_money_static);
        }
    }
}
